package JDBCUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UTIL {
		//连接数据库所用常量
		private final static String DC = "oracle.jdbc.driver.OracleDriver";
		private final static String URL = "jdbc:oracle:thin:@localhost:1521:XE";
		private final static String USER = "scott";
		private final static String PWD = "tiger";
		
		//数据库的连接
		public static Connection getConn(){
			Connection conn = null;
			try {
				Class.forName(DC);
				conn = DriverManager.getConnection(URL, USER, PWD);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return conn;
		}
		
		//数据库的关闭
		public static void closeConn(ResultSet rs,PreparedStatement ps,Connection conn) throws SQLException{
			if(rs != null) {
				rs.close();
			}
			if(ps != null) {
				ps.close();
			}
			if(conn != null) {
				conn.close();
			}
			
		}
}
